package com.xzh.controller;

import com.xzh.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/free")
public class FreeController {

    @RequestMapping("/toFree")
    public String freeTest(Model model) {
        User user = new User();
        user.setUser_name("张三");
        user.setUser_password("123");
        user.setSalary(300.12312312222);
        user.setHireDate(new Date());
        user.setBirthday("2024-10-16");
        model.addAttribute(user);
        return "free";
    }
    @RequestMapping("/freeForTest")
    public String freeForTest(Model model){
        User user1 =new User();
        user1.setUser_name("123");
        user1.setUser_password("123");

        User user2 =new User();
        user2.setUser_name("123");
        user2.setUser_password("123");

        User user3 =new User();
        user3.setUser_name("123");
        user3.setUser_password("123");

        List<User> list=new ArrayList<>();
        list.add(user1);
        list.add(user3);
        list.add(user2);
        model.addAttribute("list",list);
        return "free";
    }

    @RequestMapping("/freeSessionTest")
    public String freeSessionTest(HttpSession session){
        User user1 =new User();
        user1.setUser_name("123");
        user1.setUser_password("123");
        session.setAttribute("user",user1);
        return "free";
    }
}
